


import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter_bsbdj/bmob/bmob/bmob.dart';
import 'package:flutter_bsbdj/data_base/data_base.dart';

import 'homePager.dart';

class Welcome extends StatefulWidget{
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return WelcomeWidget();
  }

}

class WelcomeWidget extends State<Welcome>{
//  int second_index=5;
  int changeIndex=0;
  Timer timer;
  TextStyle _textStyle=TextStyle(color: Colors.blueAccent,fontWeight: FontWeight.normal);

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    timer=Timer.periodic(Duration(milliseconds: 50), (sd){
      setState(() {
        changeIndex+=1;
      });
      if(changeIndex>=100){
        _openMain();
      }
    });
    Bmob.initMasterKey("a37db715b23b6e24351cc8059cef66cf", "142ed656121a5cfe206e0f9eadf839f0", "");
    DataBaseUtil.getInstance().createDataBase();
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      body: Stack(
        children: <Widget>[
          Container(
            width: MediaQuery.of(context).size.width,
            height: MediaQuery.of(context).size.height,
            child: Image.asset("images/music_bg.jpg",fit: BoxFit.fill,),
          ),
          Container(
            alignment: Alignment.bottomRight,//设置内容的显示对其方式为 靠右下角显示
            child: Container(
              width: 60,
              height: 60,
              decoration: BoxDecoration(
//                color: Colors.green,//设置背景色，为了看清控件位置设置，在界面完成之后屏蔽此代码
                borderRadius: BorderRadius.all(Radius.circular(30)),//设置圆角
              ),
              alignment: Alignment.center,//居中显示
              margin: EdgeInsets.all(25),//设置外边距
              child: GestureDetector(
                child: Stack(
                  children: <Widget>[
                    Container(
                      alignment: Alignment.center,
                      child: CircularProgressIndicator(
                        value: changeIndex/100,
                        strokeWidth: 1,
                      ),
                    ),
                    Container(
                      alignment: Alignment.center,
                      child: Text("跳过"),
                    ),
                  ],
                ),
                onTap: (){
                  _openMain();
                },
              ),
            ),
          ),
          Container(
            alignment: Alignment.center,
            margin: EdgeInsets.only(top: 260),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Container(
                  height: 50,
                  child: Text("flutter学习项目",style: _textStyle,),
                ),
                Container(
                  height: 50,
                  child: Text("数据来源于网络",style: _textStyle,),
                ),
                Container(
                  height: 50,
                  child: Text("仅供flutter学习使用不得作为任何商业用途",style: _textStyle,),
                ),
                Container(
                  height: 50,
                  child: Text("如果侵权，联系删除",style: _textStyle,),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }

  void _openMain(){
    Navigator.pushAndRemoveUntil(context,
        MaterialPageRoute(
            builder: (context)=>MyHomePage(),
        ), (Route route)=>route==null);
    timer?.cancel();
    timer=null;
  }

}